#ifndef __VersionManager__
#define __VersionManager__

#include "plugin.h"
#include "serialized_object.h"
#include "project.h"

#include "vm_manager.h"

/**
 * @class VersionManager
 * Version Manager plugin class
 */
class VersionManager : public IPlugin
{
private:
	wxMenuItem* m_separatorItem;

public:
	VersionManager(IManager *manager);
	~VersionManager();

	//--------------------------------------------
	//Abstract methods
	//--------------------------------------------
	virtual wxToolBar *CreateToolBar(wxWindow *parent);
	virtual void CreatePluginMenu(wxMenu *pluginsMenu);
	virtual void HookPopupMenu(wxMenu *menu, MenuType type);
	virtual void UnHookPopupMenu(wxMenu *menu, MenuType type);
	virtual void UnPlug();

protected :
	ProjectPtr GetSelectedProject() const;
	wxWindow*  GetTopWindow() const { return m_mgr->GetTheApp()->GetTopWindow(); }

	// Events
	void OnProjectSettings(wxCommandEvent& event);
	void OnGlobalSettings(wxCommandEvent& event);
	void OnManage(wxCommandEvent& event);
	void OnDeliver(wxCommandEvent& event);
	void OnBuildStarting(wxCommandEvent& event);
};

/**
 * @class VMProjectSettings
 * Project settings and version
 */
class VMProjectSettings : public SerializedObject
{
private :
	versionmgr::VersionData  m_versionData;

public:
	VMProjectSettings()
	{
	}

	VMProjectSettings(const versionmgr::VersionData& versionData)
	: m_versionData(versionData)
	{
	}

	void SetVersionData(const versionmgr::VersionData& versionData) { m_versionData = versionData; }
	const versionmgr::VersionData& GetVersionData() const { return m_versionData; }
	versionmgr::VersionData& GetVersionData() { return m_versionData; }

	virtual void Serialize(Archive &arch);
	virtual void DeSerialize(Archive &arch);
};

/**
 * @class VMGlobalSettings
 * global settings : used by default if the project is going to be managed
 */
class VMGlobalSettings : public SerializedObject
{
private	:
	versionmgr::Settings m_settings;
	wxString             m_sSvnPath;
	bool                 m_bUseExternalSettingFile;

public:
	VMGlobalSettings()
	: m_sSvnPath(wxT("svn"))
	, m_bUseExternalSettingFile(false)
	{
	}

	void SetSvnPath(const wxString& sSvnPath) { m_sSvnPath = sSvnPath; }
	const wxString& GetSvnPath() const { return m_sSvnPath; }
	void SetSettings(const versionmgr::Settings& settings) { m_settings = settings; }
	const versionmgr::Settings& GetSettings() const { return m_settings; }
	bool UseExternalSettingFile() const { return m_bUseExternalSettingFile; }
	void UseExternalSettingFile(bool bUse) { m_bUseExternalSettingFile = bUse; }

	virtual void Serialize(Archive &arch);
	virtual void DeSerialize(Archive &arch);
};

/**
 * @class VMProject
 * Project wrapper
 */
class VMProject
{
protected:
	IManager*          m_mgr;
	ProjectPtr         m_pProject;
	VMProjectSettings  m_data;
	bool               m_bIsManaged;
	bool               m_bUseExternalSettingFile;

public:
	VMProject(IManager* mgr, ProjectPtr pProject);

	wxString GetName() const { return m_pProject->GetName(); }
	wxFileName GetFileName() const { return m_pProject->GetFileName(); }
	bool IsManaged() const { return m_bIsManaged; }
	wxString GetVersionFullPath() const;
	const versionmgr::VersionData& GetVersionData() const { return m_data.GetVersionData(); }
	versionmgr::VersionData& GetVersionData() { return m_data.GetVersionData(); }
	void SetVersionData(const versionmgr::VersionData& versionData) { m_data.SetVersionData(versionData); }
	bool UseExternalSettingFile() const { return m_bUseExternalSettingFile; }
	void UseExternalSettingFile(bool bUse) { m_bUseExternalSettingFile = bUse; }

	bool Save(bool bWriteFile = true);

protected:
	bool Load();
};

#endif //VersionManager

